package com.hjqjl.whdemo.feature.feature0.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hjqjl.whdemo.base.BaseActivity;
import com.hjqjl.whdemo.databinding.ActivityPermissionBinding;

public class PermissionActivity extends BaseActivity {
    public static void start(Context context) {
        Intent starter = new Intent(context, PermissionActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityPermissionBinding binding = ActivityPermissionBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setTitle("权限请求");
        binding.homeTvPermissionContent.setText("CAMERA权限是否被授予："
                + PermissionUtils.isGranted(PermissionConstants.CAMERA));

        binding.homeBtnPermissionRequest.setOnClickListener(v ->
                PermissionUtils.permissionGroup(PermissionConstants.CAMERA)
                        .callback(new PermissionUtils.SimpleCallback() {
                            @Override
                            public void onGranted() {
                                binding.homeTvPermissionContent.setText("权限申请成功");
                                ToastUtils.showShort("权限申请成功");
                            }

                            @Override
                            public void onDenied() {
                                binding.homeTvPermissionContent.setText("权限申请失败");
                                ToastUtils.showShort("权限申请失败");
                            }
                        })
                        .request());
    }
}
